#include "lcd.h"

#include "bsp.h"


/*sbit	cs1	=	P2^4;
sbit	rst =	P2^3;
sbit	rs	=	P2^2;
sbit	sck	=	P2^1;
sbit	sda	=	P2^0;
sbit	ps	= P2^5;	//H=4spi;L=3SPI
sbit	VDD	=	P4^1;
sbit	VLED=	P4^3;*/

extern const unsigned char gImage_Sample_01[1152];
extern const unsigned char gImage_Sample_02[1152];
extern const unsigned char gImage_Sample_03[1152];

#define delay_ms(x) HAL_Delay(x)
#define delay_ss(x) HAL_Delay(1000*x)
#define pauseBig()  HAL_Delay(3000)
#define pauseSmall() HAL_Delay(800)
//#define  __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop()
void _nop_(){
	uint32_t i = 0;
	for(i = 0; i < 3; i++){
		__nop();
	}
}

void write_com(unsigned char byte)
{
	unsigned char i;
	//HAL_GPIO_WritePin(LCD_CSB_GPIO_Port, LCD_CSB_Pin, GPIO_PIN_RESET);
	//rs=0;
	HAL_GPIO_WritePin(LCD_A0_GPIO_Port, LCD_A0_Pin, GPIO_PIN_RESET);
	_nop_();_nop_();
	for(i=0;i<8;i++)
		{
			//sda=(bit)(byte&0x80);
			HAL_GPIO_WritePin(LCD_SID_GPIO_Port, LCD_SID_Pin, (byte&0x80) ? GPIO_PIN_SET : GPIO_PIN_RESET);
			byte=byte<<1;
			_nop_();
			_nop_();
			//sck=0;
			HAL_GPIO_WritePin(LCD_SCLK_GPIO_Port, LCD_SCLK_Pin, GPIO_PIN_RESET);
			_nop_();
			_nop_();
			//sck=1;
			HAL_GPIO_WritePin(LCD_SCLK_GPIO_Port, LCD_SCLK_Pin, GPIO_PIN_SET);
			_nop_();
			_nop_();
		 }
		
		 //HAL_GPIO_WritePin(LCD_CSB_GPIO_Port, LCD_CSB_Pin, GPIO_PIN_SET);
}

//serial 4-SPIд˽ߝû
void write_dat(unsigned char byte)
{
	unsigned char i;
	//HAL_GPIO_WritePin(LCD_CSB_GPIO_Port, LCD_CSB_Pin, GPIO_PIN_RESET);
	//rs=1;
	HAL_GPIO_WritePin(LCD_A0_GPIO_Port, LCD_A0_Pin, GPIO_PIN_SET);
	_nop_();_nop_();
	for(i=0;i<8;i++)
		{
			//sda=(bit)(byte&0x80);
			HAL_GPIO_WritePin(LCD_SID_GPIO_Port, LCD_SID_Pin, (byte&0x80) ? GPIO_PIN_SET : GPIO_PIN_RESET);
			byte=byte<<1;
			_nop_();
			_nop_();
			//sck=0;
			HAL_GPIO_WritePin(LCD_SCLK_GPIO_Port, LCD_SCLK_Pin, GPIO_PIN_RESET);
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			//sck=1;
			HAL_GPIO_WritePin(LCD_SCLK_GPIO_Port, LCD_SCLK_Pin, GPIO_PIN_SET);
			_nop_();
			_nop_();
		 }
		//HAL_GPIO_WritePin(LCD_CSB_GPIO_Port, LCD_CSB_Pin, GPIO_PIN_SET);
}
void line(unsigned char da)
{
	unsigned char i,j;
	for(i=0xb0;i<0xbc;i++)	//96ѐ
	{
	  write_com(i);			
	  write_com(0x10);	
	  write_com(0x00);
	  for(j=0;j<96;j++)		//128Ϊ}
	  {
	    write_dat(da);
			write_dat(da);
	  }
	}
}

void ver(unsigned char da,unsigned char db,unsigned char dc,unsigned char dd)
{
	unsigned char i,j;
	for(j=0;j<12;j++)	
	{
		write_com(0xb0+j);	//64ѐΪ}
		write_com(0x10);	
	  write_com(0x00);
		for(i=0;i<24;i++)		//128Ϊ}ì128/4=32
		{
	 		write_dat(da);write_dat(da);
			write_dat(db);write_dat(db);
			write_dat(dc);write_dat(dc);
			write_dat(dd);write_dat(dd);
		}
	}
}
//ͼюДʾ
void lcd_image(unsigned char *p)
{
	unsigned char i,j;	
	for (i=0xb0;i<0xbc;i++)
	{
	  write_com(i);				// RAM page address
	  write_com(0x10);		// RAM column address most address
	  write_com(0x00);		// RAM column address least address
	  for(j=0;j<96;j++)
	  {
		write_dat(*p);
		write_dat(*p++);
	  }
	}
}

unsigned char  image_yes[] = 
{
/*--  ַɫһعͼбúD:\IC\Ӣ˔·ԌͼƬ\9664\9696.bmp  --*/
/*--  ࠭׈xٟ׈=96x96  --*/
0xFF,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,0x01,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,
0x01,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,0x01,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,
0x01,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,0x01,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,
0x01,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,0x01,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,
0x01,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,0x01,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,
0x01,0x01,0x01,0x01,0xF1,0xE1,0xC1,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,
0xFF,0x00,0x00,0x00,0xFF,0xEF,0xCF,0x8F,0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,
0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,
0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,
0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,
0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,
0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,0x0F,0x0E,0x0C,0x08,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0xFF,0xEF,0xCF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F,0xEF,0xCF,0x8F,
0x0F,0x0E,0x0C,0x08,0xFF,0xEF,0xCF,0x8F,0x0F,0x0E,0x0C,0x08,0x00,0x00,0x00,0xFF,
0xFF,0x80,0x80,0x80,0x8F,0x8F,0x8F,0x8F,0x8F,0x8E,0x8C,0x88,0x8F,0x8F,0x8F,0x8F,
0x8F,0x8E,0x8C,0x88,0x8F,0x8F,0x8F,0x8F,0x8F,0x8E,0x8C,0x88,0x8F,0x8F,0x8F,0x8F,
0x8F,0x8E,0x8C,0x88,0x8F,0x8F,0x8F,0x8F,0x8F,0x8E,0x8C,0x88,0x8F,0x8F,0x8F,0x8F,
0x8F,0x8E,0x8C,0x88,0x8F,0x8F,0x8F,0x8F,0x8F,0x8E,0x8C,0x88,0x8F,0x8F,0x8F,0x8F,
0x8F,0x8E,0x8C,0x88,0x8F,0x8F,0x8F,0x8F,0x8F,0x8E,0x8C,0x88,0x8F,0x8F,0x8F,0x8F,
0x8F,0x8E,0x8C,0x88,0x8F,0x8F,0x8F,0x8F,0x8F,0x8E,0x8C,0x88,0x80,0x80,0x80,0xFF,
};
unsigned char  image_cs[] = 
{
/*--  ַɫһعͼбúD:\IC\Ӣ˔·ԌͼƬ\9664\9664-cs - رѾ.bmp  --*/
/*--  ࠭׈xٟ׈=96x96  --*/
0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xC0,0xC0,
0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x20,0x60,0xC0,0x80,0x00,0x00,0x00,0xE0,0xE0,0x00,0x00,0x00,0x80,0xC0,
0x40,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xFC,0x0E,0x07,0x03,0x01,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x1E,0x3F,0x71,0xE0,0xC0,0xC0,
0x80,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x8C,0x8C,0x8C,0x8C,0x8C,
0x8C,0x8C,0x8C,0x8C,0x8C,0x8C,0x8C,0x8C,0x9F,0x9F,0x80,0xF0,0x78,0x00,0x00,0x0F,
0x0F,0x03,0x03,0xFB,0xFB,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,
0xFB,0x03,0x03,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x1F,0x3C,0x70,0x60,0xE0,0xC0,
0xC0,0xC0,0xC0,0xC0,0xC0,0x60,0x60,0x00,0x00,0x00,0x30,0x60,0xC0,0xC0,0xC0,0xC1,
0xC1,0x63,0x7F,0x3E,0x00,0x00,0x00,0x30,0x30,0x30,0x31,0xB1,0xFD,0xFD,0x31,0x31,
0x31,0x31,0x31,0x31,0x31,0x31,0xFD,0xFD,0x31,0x31,0x31,0x30,0x30,0x00,0x00,0x00,
0x00,0xF8,0xF8,0x1B,0x1B,0x19,0x19,0x19,0x19,0xFF,0xFF,0x19,0x19,0x19,0x99,0x99,
0x9B,0x98,0xF8,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x06,0x07,0x03,0x03,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00,0x01,0x01,
0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xFF,
};
unsigned char  image[] = 
{
/*--  ַɫһعͼбúD:\YS436\Desktop\9696.bmp  --*/
/*--  ࠭׈xٟ׈=96x96  --*/
0x00,0x00,0x00,0x80,0xC0,0xE0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0xC0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xAB,0xAB,0xAB,0xAB,0xAB,0xAB,0xAB,0xAB,0x00,0x00,0x00,0x00,0x00,0xF0,
0xF6,0x57,0x57,0x57,0x57,0x57,0x57,0x57,0xF6,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFE,0xCE,0xB6,0xB6,0xB6,0x6E,0xFE,0xE6,0xF6,0x06,0xF6,0xE6,
0xFE,0x0E,0xF6,0xF6,0xF6,0x0E,0xFE,0x06,0xB6,0xB6,0xB6,0xCE,0xFE,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD0,0xD0,0xE0,0x38,0x38,
0xE0,0xD0,0xD0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0F,0x0E,0x0D,0x0D,0x0D,0x0E,0x0F,0x0F,0x0F,0x0C,0x0F,0x0F,
0x0F,0x0E,0x0D,0x0D,0x0D,0x0E,0x0F,0x0C,0x0F,0x0F,0x0F,0x0F,0x0F,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x01,0x07,0x07,
0x01,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFF,0xC1,0xBE,0xBE,0xBE,0xC1,0xFF,0x83,0xF7,0xFB,0xFB,0x87,
0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x7F,0x3E,0x1C,0x1C,0x08,0x00,0x00,0x7F,0x49,
0x49,0x49,0x41,0x00,0x7C,0x08,0x04,0x04,0x78,0x00,0x20,0x54,0x54,0x78,0x40,0x00,
0x00,0x00,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x25,0x25,0x25,0x25,0x25,0x25,0x25,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x91,0xB3,0xA6,0xAC,0xB9,0x91,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xF0,0xF0,0xF0,0xF0,0x00,0xF0,0xF0,0xF0,0x00,0xF0,0xF0,0x00,0xF0,
0xF0,0x00,0xF0,0x00,0xF0,0x00,0xF0,0x00,0xF0,0x00,0xF0,0x00,0xF0,0x00,0xF0,0x00,
0xF0,0x00,0x00,0x00,0x00,0x90,0x48,0x48,0x48,0x30,0x00,0x38,0x28,0x28,0x28,0xC8,
0x00,0x00,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x20,0xBF,0xBF,0x20,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x01,0x01,0x00,0x01,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x02,0x00,0x01,0x02,0x02,0x02,0x01,
0x00,0x00,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xBE,0xBF,0x89,0x89,0xBF,0xBE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x9E,0x9E,0x9E,0x9E,0x9E,0x9E,0x9E,0x9E,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0xC1,0xC1,0xC1,0xC1,0xC1,0xC1,0xC1,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xA0,0xBF,0xBF,0x84,0x8C,0xBF,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0xFC,0x00,0x00,0x00,0xC8,0x24,0x24,0x24,0x18,0x00,0xF8,0x04,0x24,0x04,0xF8,
0x00,0x18,0x3C,0x24,0x3C,0x18,0x00,0x00,0xF8,0x04,0x04,0x04,0x88,0x00,0x00,0x00,
0x00,0x00,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x20,0x3F,0x3F,0x20,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
0x41,0x21,0x41,0x80,0x00,0x01,0x21,0xE1,0x01,0x01,0x00,0x00,0x81,0x81,0x01,0x00,
0x00,0x80,0x00,0x80,0x80,0x00,0x00,0x80,0x80,0x01,0x81,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x07,0x0F,0x1F,0x1F,0x0F,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,
0x02,0x02,0x02,0x0F,0x00,0x00,0x08,0x07,0x08,0x00,0x00,0x04,0x0A,0x0A,0x0F,0x08,
0x00,0x0F,0x01,0x00,0x00,0x01,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,0x00,0x00,0x00,
0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x1F,
0x1F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
/* contrast values */
const unsigned char 	ConstrstReg		= 	0x81;
const unsigned char 	ContrastMax 	= 	63;
const unsigned char 	ContrastMin 	= 	0;
unsigned char 				contrast 			= 	20;

void reset_lcm(void)
{
	//cs1=0;	
	HAL_GPIO_WritePin(LCD_CSB_GPIO_Port, LCD_CSB_Pin, GPIO_PIN_RESET);
	//rst=0;			//ģࠩشλ
	HAL_GPIO_WritePin(LCD_RST_GPIO_Port, LCD_RST_Pin, GPIO_PIN_RESET);
	delay_ms(100);
	//rst=1;
	HAL_GPIO_WritePin(LCD_RST_GPIO_Port, LCD_RST_Pin, GPIO_PIN_SET);
	
}


void __contrast_add(void){	
	if(contrast < ContrastMax){
		contrast++;
		write_com(ConstrstReg);
		write_com(contrast);	
	}	
}

void __contrast_dec(void){
	if(contrast > ContrastMin){
		contrast--;
		write_com(ConstrstReg);
		write_com(contrast);	
	}	
}


void init_lcm(void)
{
	write_com(0xae);
	write_com(0x38);	//FR FREQUENCY
	write_com(0x7C);  //70 HZ;4 Booster

	write_com(0x48);	//display duty select:
	write_com(96);		//duty=96

	write_com(0xa0);  // adc direction: seg0-seg95
	write_com(0xc8);	// com direction: com127-com32
	write_com(0x40);	// initial display line
	write_com(0x00);
	write_com(0x44);	//com0 register select:
	write_com(0x00);	//com0=0 line

	write_com(0xab);	//oscillator on start
	write_com(0x67);
	write_com(0x27);	//regulator resistor select: 1+Rb/Ra=26H
	write_com(0x81);	//electronic volume register select:
	write_com(contrast);		//ʵӢ12.1V mÛֵ12.024V
	delay_ms(200);

	write_com(0x55);	//bias select(0x54:1/9;   0x55:1/10;   0x56:1/11)
  write_com(0xf3);
	write_com(0x04);
	write_com(0x93);
	write_com(0x2C);	//Power control
	delay_ms(200);
	write_com(0x2e);
	delay_ms(200);
	write_com(0x2f);
	delay_ms(200);

	
	write_com(0xaf);	//display on

	write_com(0xa5); 	//display full
  write_com(0xa4);	//Entire Display OFF
  delay_ms(200);

}


uint8_t lcdTransfering = 0;

uint8_t isLcdTransfering(void) {
	return lcdTransfering;
}

uint8_t pause = 0;

uint8_t isLcdPause(void) {
	return pause;
}

void setLcdPause(uint8_t status) {
	if(status ) {
		pause = 1;
	} else {
		pause = 0;
	}
}

void toggleLcdPause(void) {
	if(pause == 0) {
		pause = 1;
	} else {
		pause = 0;
	}
}

void keyPause(uint32_t time) {
	
	while(time--) {
		HAL_Delay(1);
		while(pause) {HAL_Delay(1);}
	}	
}

void testST7571 (void)
{
	HAL_GPIO_WritePin(LCD_PSI_GPIO_Port, LCD_PSI_Pin, GPIO_PIN_SET);
	HAL_Delay(100);

	HAL_GPIO_WritePin(LCD_SCLK_GPIO_Port, LCD_SCLK_Pin, GPIO_PIN_SET);
	HAL_GPIO_WritePin(LCD_SID_GPIO_Port, LCD_SID_Pin, GPIO_PIN_SET);

	setLcdPower(ENABLE);
	
	reset_lcm();
	
	
	//cs1=0;
	HAL_GPIO_WritePin(LCD_CSB_GPIO_Port, LCD_CSB_Pin, GPIO_PIN_RESET);
	HAL_Delay(100);
	init_lcm();
	while(1)
	{
		/*pauseSmall();
		lcdTransfering = 1;
		line(0xff);		//ȫД
		lcdTransfering = 0;
		//pauseBig();
		keyPause(2000);
		//while(1);

		
		lcdTransfering = 1;line(0x11);lcdTransfering = 0;keyPause(800);
		lcdTransfering = 1;line(0x22);lcdTransfering = 0;keyPause(800);
		lcdTransfering = 1;line(0x44);lcdTransfering = 0;keyPause(800);
		lcdTransfering = 1;line(0x88);lcdTransfering = 0;keyPause(800);
		
		lcdTransfering = 1;ver(0xff,0x00,0x00,0x00);lcdTransfering = 0;keyPause(800);
		lcdTransfering = 1;ver(0x00,0xff,0x00,0x00);lcdTransfering = 0;keyPause(800);
		lcdTransfering = 1;ver(0x00,0x00,0xff,0x00);lcdTransfering = 0;keyPause(800);
		lcdTransfering = 1;ver(0x00,0x00,0x00,0xff);lcdTransfering = 0;keyPause(800);

		lcdTransfering = 1;
		lcd_image(image_yes);//ͼю
		lcdTransfering = 0;
		keyPause(2000);
//		lcd_image(image);//ͼю
//		pauseBig();*/
		
		//gImage_Sample_01
		lcdTransfering = 1;
		lcd_image((unsigned char *)gImage_Sample_01);//ͼю
		lcdTransfering = 0;
		keyPause(2000);
		
		lcdTransfering = 1;
		lcd_image((unsigned char *)gImage_Sample_02);//ͼю
		lcdTransfering = 0;
		keyPause(2000);
		
		lcdTransfering = 1;
		lcd_image((unsigned char *)gImage_Sample_03);//ͼю
		lcdTransfering = 0;
		keyPause(2000);
		
		//HAL_GPIO_WritePin(LCD_CSB_GPIO_Port, LCD_CSB_Pin, GPIO_PIN_SET);
		//lcd_image(image_cs);pauseBig();
		//cs1=0;
		//HAL_GPIO_WritePin(LCD_CSB_GPIO_Port, LCD_CSB_Pin, GPIO_PIN_RESET);
		
	}  
}
